
import java.util.Date;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import tabletree.*;
import filesystem.*;



public class Test 
{

	
	public static void main(String[] args) throws InterruptedException 
	{ 
		Directory root = new Directory("root", "Wang", null, new Date());
		Directory windows = new Directory("Windows", "Liu", root, new Date());
		Directory myDocument = new Directory("MyDocument", "Ren", root, new Date());
		Directory myPictures = new Directory("MyPictures", "Duan", myDocument, new Date());
		

		File g = new File("a", "Zhu", root, new Date(), 5); 
		
		File a = new File("a", "huang", windows, new Date(), 11); 
		File b = new File("b", "mu", windows, new Date(), 53);
		File c = new File("c", "zhang", windows, new Date(), 47); 
		File d = new File("d", "yu", myDocument, new Date(), 94);
		File e = new File("e", "hu", myPictures, new Date(), 88); 
		File f = new File("f", "shao", myPictures, new Date(), 164);
		
        Link x = new Link(d, "x", "li", myDocument, new Date());
		Link y = new Link(windows,"y","Liu", myPictures, new Date());
		

		
		
		FileSystem fileSystem =  FileSystem.getInstance(root);
		String[] m_columnNames = {"Name", "Type", "Size", "Owner", "Created" };
		//fileSystem.showAllElements();
		FileSystemAdapter fsa = new FileSystemAdapter(fileSystem);
		fsa.addTableModelListener(new FileSystemTableModelListener());
		
		JTree tree = new JTree(fsa);
		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		tree.addTreeSelectionListener(new FileSystemTreeSelectionListener( (FileSystemAdapter) (tree.getModel())  ));

		
		JTable table = new JTable(fsa);
		

        
        JFrame frame = new JFrame("SiyiLiu");       
        frame.setPreferredSize(new Dimension(400, 300));

        
        frame.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });

        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        splitPane.setRightComponent(table);
        splitPane.setLeftComponent(tree);

    
        frame.getContentPane().add(splitPane);

        frame.pack();
        frame.setVisible(true);
		
	}
		
}
